<?php

require_once ("../src/Money.class.php");
require_once ("../src/PorteMonnaie.class.php");
require_once ("../src/MoneyExceptions.php");

class PorteMonnaieTestCase extends PHPUnit_Framework_TestCase
{
	private static $zeroEuro ;
	
	public static function setUpBeforeClass() {
		PorteMonnaieTestCase::$zeroEuro=MoneyFactory::getDefaultFactory()->createMoney(0,"EUR");
	}

	public function testAdd() {

		$f16eur = MoneyFactory::getDefaultFactory()->createMoney(16,"EUR");
		$this->assertTrue(PorteMonnaie::add(PorteMonnaieTestCase::$zeroEuro,$f16eur)->equals(MoneyFactory::getDefaultFactory()->createMoney(16,"EUR")));
	} 

	public function testRemove() {

		$f16eur = MoneyFactory::getDefaultFactory()->createMoney(16,"EUR");
		$f2eur = MoneyFactory::getDefaultFactory()->createMoney(2,"EUR");

		$this->assertTrue(PorteMonnaie::suppr($f16eur,$f2eur)->equals(MoneyFactory::getDefaultFactory()->createMoney(14,"EUR")));
	} 

	public function testRemoveMore() {

		$f16eur = MoneyFactory::getDefaultFactory()->createMoney(16,"EUR");

		try{
			
			PorteMonnaie::suppr(PorteMonnaieTestCase::$zeroEuro,$f16eur);
		}

		catch (UnexistingCurrencyException $e) {

		} 
		catch (NotEnoughMoneyException $e) {
			
		}

	} 


/*
*
*   TEST MULTI DEVISES
*
*/

public function testMultiDevisesAdd() {

	try{
		
		$f16eur = MoneyFactory::getDefaultFactory()->createMoney(16,"EUR");
		$f16dollar = MoneyFactory::getDefaultFactory()->createMoney(16,"USD");


		$this->assertTrue(PorteMonnaie::add($f16eur,$f16dollar)->equals(MoneyFactory::getDefaultFactory()->createMoney(32,"EUR")));
		$this-fail();
	}

	catch (UnexistingCurrencyException $e) {

	} 
	catch (IncompatiblesCurrenciesException $e) {
		
	}

} 

public function testMultiDevisesRemove() {

	try{
		
		$f16eur = MoneyFactory::getDefaultFactory()->createMoney(16,"EUR");
		$f6dollar = MoneyFactory::getDefaultFactory()->createMoney(6,"USD");


		$this->assertTrue(PorteMonnaie::suppr($f16eur,$f6dollar)->equals(MoneyFactory::getDefaultFactory()->createMoney(10,"EUR")));
		$this-fail();
	}

	catch (UnexistingCurrencyException $e) {

	} 
	catch (IncompatiblesCurrenciesException $e) {
		
	}

} 


/*
*
*   TEST DEVICE ABSENTE
*
*/

public function testDeviseAbsent() {

	try{
		
		$f16eur = MoneyFactory::getDefaultFactory()->createMoney(16,"EUR");
		$f6dollar = MoneyFactory::getDefaultFactory()->createMoney(6,"CFA");
		$this->assertTrue(PorteMonnaie::suppr($f16eur,$f6dollar)->equals(MoneyFactory::getDefaultFactory()->createMoney(10,"EUR")));
		$this-fail();
	}

	catch (UnexistingCurrencyException $e) {

	} 
	catch (IncompatiblesCurrenciesException $e) {
		
	}

}


/*
*
*   TEST ADD/REMOVE MULTIDEVICE
*
*/


public function testAddMultiDevise() {

	$f16eur = MoneyFactory::getDefaultFactory()->createMoney(16,"EUR");
	
	$walletEur = MoneyFactory::getDefaultFactory()->createMoney(0,"EUR");
	$walletdollar = MoneyFactory::getDefaultFactory()->createMoney(0,"USD");			

	$wallet =[$walletEur,$walletdollar];

	PorteMonnaie::addMulti($f16eur,$wallet);

	$this->assertTrue($wallet->equals( [MoneyFactory::getDefaultFactory()->createMoney(16,"EUR"), MoneyFactory::getDefaultFactory()->createMoney(0,"USD")]));
	

}


public function testRemoveMultiDevise() {

	$f6dollar = MoneyFactory::getDefaultFactory()->createMoney(6,"USD");
	
	$walletEur = MoneyFactory::getDefaultFactory()->createMoney(0,"EUR");
	$walletdollar = MoneyFactory::getDefaultFactory()->createMoney(6,"USD");			

	$wallet =[$walletEur,$walletdollar];

	PorteMonnaie::supprMulti($f6dollar,$wallet);


	$this->assertTrue($wallet->equals( [MoneyFactory::getDefaultFactory()->createMoney(0,"EUR"), MoneyFactory::getDefaultFactory()->createMoney(0,"USD")]));
	

}

	/*
*
*   TEST CONVERSION DEVICE
*
*/
public function testConversion(){
	$f6dollar = MoneyFactory::getDefaultFactory()->createMoney(6,"USD");
	$this->assertTrue(PorteMonnaie::convertTo($f6dollar,"EUR")->equals(MoneyFactory::getDefaultFactory()->createMoney(4.46,"EUR")));

}


/*
*
*   TEST GRAND NOMBRE
*
*/


public function testAddBigNumber() {

	$f6dollar = MoneyFactory::getDefaultFactory()->createMoney(gmp_init(1000000000000),"USD");
	
	$walletEur = MoneyFactory::getDefaultFactory()->createMoney(0,"EUR");
	$walletdollar = MoneyFactory::getDefaultFactory()->createMoney(0,"USD");			

	$wallet =[$walletEur,$walletdollar];

	PorteMonnaie::addMulti($f6dollar,$wallet);


	$this->assertTrue($wallet->equals( [MoneyFactory::getDefaultFactory()->createMoney(0,"EUR"), MoneyFactory::getDefaultFactory()->createMoney(1000000000000,"USD")]));
		

	}


	public function testRemoveBigNumber() {

	$f6dollar = MoneyFactory::getDefaultFactory()->createMoney(gmp_init(9000000000),"USD");
	
	$walletEur = MoneyFactory::getDefaultFactory()->createMoney(0,"EUR");
	$walletdollar = MoneyFactory::getDefaultFactory()->createMoney(gmp_init(1000000000000),"USD");			

	$wallet =[$walletEur,$walletdollar];

	PorteMonnaie::supprMulti($f6dollar,$wallet);


	$this->assertTrue($wallet->equals( [MoneyFactory::getDefaultFactory()->createMoney(0,"EUR"), MoneyFactory::getDefaultFactory()->createMoney(gmp_init(991000000000),"USD")]));
		

	}




}
?>
